package algorithm.beforestart.primary.sort;

public class firstBadVersion {

    public static int firstBadVersion(int n) {

      return   judjebadversion(1,n);


    }
    public static int firstBadVersion2(int n) {

       for (int i=0;i<=n;i++){
           if(isBadVersion(i)){
               return i;
           }
       }
        return 0;
    }

     static int  judjebadversion(int a, int b) {

        if (isBadVersion(b)&&!isBadVersion(b-1)){
            return b;
        }

        if(isBadVersion((a+b)/2)){
            if (!isBadVersion((a+b)/2-1)){
            return (a+b)/2;
            }else {
                return judjebadversion(a,(a+b)/2);
            }
        }else{
            return judjebadversion((a+b)/2,b);
        }

    }

    static boolean isBadVersion(int version) {
        if (version < 1702766719) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(firstBadVersion(2126753390));
    }
}
